package com.zy.explore.frm;

import com.zy.explore.base.jpa.OffsetRequest;
import com.zy.explore.vo.OffsetVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import javax.validation.constraints.Min;

/**
 * description 标准 offset 分页请求体
 *
 * @author ZY
 * @date 2021-05-05 18:02
 * @see OffsetVO offset 响应实体
 */
@ApiModel("标准 offset 分页请求体")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OffsetFrm implements PageableFrm {

    @ApiModelProperty(value = "offset ，从 0 开始", dataType = "int", example = "0")
    @Min(value = 0, message = "offset 不能小于 0")
    private int offset = 0;

    @ApiModelProperty(value = "每页大小", dataType = "int", example = "10")
    @Min(value = 1, message = "每页大小不能小于 1")
    private int limit = 10;

    @Override
    public Pageable toPageable() {
        return OffsetRequest.of(offset, limit);
    }

    @Override
    public Pageable toPageable(Sort sort) {
        return OffsetRequest.of(offset, limit, sort);
    }
}
